<template>
  <div class="input-group">
    <input v-model="model" :type="type" name="text" autocomplete="off" class="input" required />
    <label class="label">{{ label }}</label>
    <slot name="icon"></slot>
  </div>
</template>

<script setup lang="ts">
import type { LabelInputProps } from '@/types/components'

withDefaults(defineProps<LabelInputProps>(), { type: 'text' })

const model = defineModel({ type: String, default: '' })
</script>

<style scoped lang="scss">
.input-group {
  position: relative;
  .input {
    width: 100%;
    box-sizing: border-box;
    border: solid 1px var(--el-border-color-hover);
    border-radius: 8px;
    background: none;
    padding: 1rem 3rem 1rem 1rem;
    font-size: 1rem;
    transition: border 150ms cubic-bezier(0.4, 0, 0.2, 1);
  }

  .label {
    position: absolute;
    top: 0;
    left: 1rem;
    color: #919eab;
    pointer-events: none;
    transform: translateY(1rem);
    transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: bolder;
  }

  .input:focus {
    outline: none;
    border-color: var(--el-color-primary);
  }
  .input:focus ~ label,
  input:valid ~ label {
    transform: translateY(-50%) scale(0.8);
    background-color: #fff;
    padding: 0 0.2em;
  }
  .input:focus ~ label {
    color: var(--el-color-primary);
  }

  :deep(.el-icon) {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    user-select: none;
  }
}
</style>
